import { Bearing } from  '../scheme/bearing';
import { Component, EventEmitter, Input, Output } from '@angular/core';

@Component({
	moduleId: module.id,
	selector: 'table-with-page',
	templateUrl: 'table.component.html',
	styleUrls: ['table.component.css']
	
})
export class TableComponent{
	selectedBear: Bearing;
	pageNum 	: number = 1;
	pageSize	: number = 3;
	totalRecords: number = 6;

	@Input() bearings: Bearing[];

	@Output() onChoose = new EventEmitter<Bearing>();

	goPrevPage():void {
		if( this.pageNum === 1 ){
			alert('没有上一页');
		}else{
			this.pageNum--;
		}
	};

	goNextPage():void {
		let totalPages = Math.ceil(this.totalRecords/this.pageSize );
		if( this.pageNum === totalPages ){
			alert('没有下一页');
		}else{
			this.pageNum++;
		}
	};

	onSelect(bear: Bearing) {
		this.selectedBear = bear;
		this.onChoose.emit(bear);
	};
 }
